package Day2025_03_06;

import java.util.PriorityQueue;

public class LeetCode1046 {
    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> heap = new PriorityQueue<>((a, b) -> b - a);
        for (int x : stones) heap.offer(x);
        while (heap.size() > 1) {
            int a = heap.poll();
            int b = heap.poll();
            heap.offer(a -  b);
        }
        if (heap.size() == 0) return 0;
        else return heap.poll();
    }
}
